/**
 * @ author: 汪孟苹 组件
 */
define(["jquery"],function($){
	var pageTab = {};

	/**
	 * 数据处理
	 * @param  {[num]} curIndex [当前索引]           	必填
	 * @param  {[arr]} data     [数据]				 	必填
	 * @param  {[num]} width    [大box的宽度]			必填
	 * @param  {[num]} widthLi  [每一个小li的宽度]		可填 默认104px
	 * @param  {[num]} distance [ul和ul之间的距离]		可填 默认10px
	 */
	var handleData = function(options,callback){
		var arr = [], arr1 = [], arr2 = [], arr3 = [];
		var curIndex = Number(options.curIndex), 
			data = options.data, 
			width = options.width, 
			clickable = options.clickable == undefined ? false : options.clickable,
			widthLi = options.widthLi == undefined ? 100 : options.widthLi, 
			distance = options.distance == undefined ? 5 : options.distance;
		var baseLen = 2;  // 前后各保留2个(若以后变化，需要提出来作为参数)
		var num = ( width - 2*baseLen*widthLi - distance*2 ) / widthLi;
		var centerLen = num >= 7 ? 7 : num >= 5 ? 5 : 3; // 中间可显示的个数,默认3个（小屏幕：3；中屏幕：5；大屏幕：7）
		var showNum = centerLen + 2*baseLen;
		var total = data.length;
		if(total <= showNum){
			for(var i = 0; i < total; i++){
				arr1.push( callback(data[i],i,curIndex,clickable) );
			}			
			arr = [arr1];
		}else{
			if(curIndex < baseLen + Math.ceil(centerLen / 2)){
				for(var i = 0; i < baseLen + centerLen; i++){
					arr1.push( callback(data[i],i,curIndex,clickable) );
				}
				for(i = total - baseLen; i < total; i++){
					arr2.push( callback(data[i],i,curIndex,clickable) );
				}
				arr = [arr1,arr2];
			}else if(curIndex > total - (centerLen + baseLen)){
				for(var i = 0; i < baseLen; i++){
					arr1.push( callback(data[i],i,curIndex,clickable) );
				}
				for(i = total - (centerLen+baseLen); i < total; i++){
					arr2.push( callback(data[i],i,curIndex,clickable) );
				}
				arr = [arr1,arr2];
			}else{
				for(var i = 0; i < baseLen; i++){
					arr1.push( callback(data[i],i,curIndex,clickable) );
				}
				for(var i = curIndex - (centerLen - 1) / 2; i <= curIndex + (centerLen - 1) / 2; i++){
					arr2.push( callback(data[i],i,curIndex,clickable) );
				}
				for(var i = total-baseLen; i < total; i++){
					arr3.push( callback(data[i],i,curIndex,clickable) );
				}
				arr = [arr1,arr2,arr3];
			};
		}
		return arr;
	};

	pageTab.handleData = function(options,callback){
		return handleData(options,callback);
	}

	return pageTab;
});